package com.jiutong.meipengdai.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jiutong.meipengdai.R;
import com.jiutong.meipengdai.entity.LoanBean;

import java.util.List;


/**
 * 作用: 贷款ListView适配器
 * Created by weicheng on 2017/6/1.
 */

public class LoanItemAdapter extends BaseAdapter {

    private LayoutInflater layoutInflater;
    private Context context;
    private List<LoanBean> mlist;

    public LoanItemAdapter(Context context, List list) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.mlist = list;
    }

    @Override
    public int getCount() {
        return null == mlist ? 0 : mlist.size();
    }

    @Override
    public Object getItem(int position) {
        return mlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.loan_item_list, null);
            holder = new ViewHolder();
            holder.view = (View) convertView.findViewById(R.id.loan_state);
            holder.tv_loan_money = (TextView) convertView.findViewById(R.id.tv_loan_money);
//            holder.tv_item_loan_time = (TextView) convertView.findViewById(R.id.tv_item_loan_time);
//            holder.tv_item_loan_num = (TextView) convertView.findViewById(R.id.tv_item_loan_num);
//            holder.tv_loan_repay = (TextView) convertView.findViewById(R.id.tv_loan_repay);
//            holder.iv_loan_repay = (ImageView) convertView.findViewById(R.id.iv_loan_repay);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (mlist.get(position).getLoan_rePay().equals("还款中")) {
            holder.view.setBackgroundResource(R.color.orange);
           holder.tv_loan_repay.setTextColor(Color.parseColor("#f09738"));
        } else if (mlist.get(position).getLoan_rePay().equals("审核中")) {
            holder.view.setBackgroundResource(R.color.green);
           holder.tv_loan_repay.setTextColor(Color.parseColor("#009944"));
        } else if (mlist.get(position).getLoan_rePay().equals("已还清")) {
            holder.view.setBackgroundResource(R.color.default_gray);
           holder.tv_loan_repay.setTextColor(Color.parseColor("#808080"));
        }
        holder.tv_loan_repay.setText(mlist.get(position).getLoan_rePay());
        holder.tv_item_loan_num.setText(mlist.get(position).getNum());
        holder.tv_loan_money.setText(mlist.get(position).getMoney());
        holder.tv_item_loan_time.setText(mlist.get(position).getTime());
        return convertView;
    }

    static class ViewHolder {
        private View view;
        private TextView tv_loan_money;
        private TextView tv_item_loan_time;
        private TextView tv_item_loan_num;
        private TextView tv_loan_repay;
        private ImageView iv_loan_repay;
    }
}
